<template>
	<view style="background-color: #f3f4f5;" class="">
		<u-navbar :is-back="true" title="基础资料" back-icon-color="#FFFFFF" title-color="white" :background="background"
			:border-bottom="false">
			<view class="navbar-right" slot="right">
				<view class="" style="margin-right: 20rpx;color: #FFFFFF;" @click="openinfo('/pages/tabBar/my/editInitial')">
					编辑
				</view>
			</view>
		</u-navbar>
		<view class="u-p-15 u-font-12" style="background-color: #f3f4f5;color: #b2b2b2;">
			以下信息为医生认证必填信息
		</view>
		<u-cell-group class="u-m-b-26">
			<view class="u-padding-26">
				<image class="u-avatar-demo" :src="oss+data.avatar" mode="aspectFill"></image>
				<p @click='upload()' @tap="chooseAvatar" style="color: #c0c4cc;float: right;line-height: 100rpx;">更换
				</p>
			</view>
		</u-cell-group>
		<u-cell-group class="u-m-b-26 u-p-l-26 u-p-r-26" style="background-color: #FFFFFF;">
			<u-cell-item title="姓名" :value="data.nickname" :arrow="false"></u-cell-item>
			<u-cell-item title="性别" :arrow="false" :value="data.gender?'男':'女'"></u-cell-item>
			<u-cell-item title="联系电话" :arrow="false" :value="data.mobile"></u-cell-item>
		</u-cell-group>
		<u-cell-group class="u-m-b-26 u-p-l-26 u-p-r-26" style="background-color: #FFFFFF;">
			<u-cell-item title="执业机构" :value="data.workingagency" :arrow="false"></u-cell-item>
			<u-cell-item title="当前职称" :value="data.position_name" :arrow="false"></u-cell-item>
			<u-cell-item title="从业时间" :value="$u.timeFormat(data.workingtime, 'yyyy年mm月dd日')" :arrow="false">
			</u-cell-item>
			<u-cell-item title="擅长项目" :value="data.shan" :arrow="false"></u-cell-item>
		</u-cell-group>
		<u-cell-group class="u-m-b-26 u-p-l-26 u-p-r-26" style="background-color: #FFFFFF;">
			<u-cell-item title="医生简介" :arrow="false" :value="data.description"></u-cell-item>
			<u-cell-item title="擅长项目简介" :value="data.selfthing" :arrow="false"></u-cell-item>
		</u-cell-group>
	</view>
</template>

<script>
	import {
		ossAccessid,
		ossHost,
		ossSignature,
		ossPolicyBase64
	} from "@/common/ossUploadfile.js"
	export default {
		// 监听页面加载
		onLoad() {
			this.getINit();
		},

		onShow() {},
		data() {
			return {

				data: '',
				oss: 'http://zjmeifeng.oss-cn-beijing.aliyuncs.com/',
				fileList: [{
					url: 'http://pics.sc.chinaz.com/files/pic/pic9/201912/hpic1886.jpg',
				}],
				// 当前职称选择
				atShow: false,
				// 职称 选择的  从业时间
				title: '选择职称',
				time: '请选择开始从业时间',
				// 职称列表
				selector: [],
				// 接口数据，职称列表
				titleList: [],

				showTime: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},

				background: {
					backgroundColor: '#00a8ff',
				},
				list: [{
						name: '女士',
						disabled: false
					},
					{
						name: '男士',
						disabled: false
					}
				],
				value: 'orange',
				// 头像地址
				avatar: '',
				// 真实姓名
				nickname: '',
				// 执业机构名称
				workingagency: '',
				// 执业机构地区
				workingagency_area: '',
				// 执业机构详细地址
				workingagency_address: '',
				// 职称
				positions_id: '',
				// 执业开始时间
				workingtime: '',
				// 擅长项目ID
				collection_ids: '',
				// 简介 
				description: '',
				selfthing: ''

			}
		},
		created() {
			// 监听从裁剪页发布的事件，获得裁剪结果
			uni.$on('uAvatarCropper', path => {
				console.log(path)
				this.avatar = path;
				console.log(path);
				// 获取当前时间戳
				let timestamp = (new Date()).valueOf();
				let nameStr = "test1/" + timestamp + "/" + path;
				console.log(nameStr);
				let titleImage = ossHost + nameStr;
				// 头像地址
				// this.avatar = titleImage;
				console.log("titleImage: ", titleImage);
				uni.uploadFile({
					url: ossHost,
					filePath: path,
					fileType: "image",
					name: 'file',
					formData: {
						"key": nameStr,
						'OSSAccessKeyId': ossAccessid,
						'policy': ossPolicyBase64,
						'signature': ossSignature,
						'success_action_status': 200
					},
					header: {},
					complete: (res) => {
						console.log(res);
						console.log("头像上传")
					},
					success: obsRes => {
						uni.hideLoading();
						console.log(obsRes);
						if (obsRes.statusCode == 200) {
							uni.showToast({
								title: "图片上传成功",
								duration: 800
							})
						} else {
							uni.showToast({
								title: "上传失败,请检查网络或服务器",
								icon: "none",
							})
						}
					},
					fail: err => {
						console.log("报错")
						uni.hideLoading()
						uni.showToast({
							title: "网络错误请检查," + JSON.stringify(err),
							icon: "none",
							duration: 4000
						})
					},
				});
			})
		},
		methods: {
			// 获取基础资料
			getINit() {
				this.$apiVipCentre.detailG({}).then((res) => {
					console.log('request data data', res.data.data);
					let data = res.data.data;
					data["shan"] = '';
					for (let key in data.collections) {
						console.log(data.collections[key].name);
						data["shan"] += data.collections[key].name + " ";
					}
					console.log(data);
					this.data = data;
				}).catch((err) => {
					console.log('request fail', err);
				})
			},

			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				console.log(e);
			},
			// 选择职称
			pickerShow() {
				this.atShow = true;
			},
			// 选择时间
			pickerTimeShow() {
				this.showTime = true;
			},
			confirmTime(e) {
				this.time = e.year + "年" + e.month + "月" + e.day + "日"
				console.log("时间戳");
				// this.workingtime = 
				// 传入上个月时间戳
				let dt = e.year + "-" + e.month + "-" + e.day + " " + "00:00";
				var timestamp1 = (new Date(dt)).getTime() / 1000
				console.log("时间戳:", timestamp1);
				console.log("日期:", dt);
				this.workingtime = timestamp1;
			},
			confirmSelector(e) {
				console.log(e);

				this.positions_id = parseInt(e) + 1;
				this.title = this.selector[e];
			},
			// 上传头像
			upload() {
				console.log(1)
			},

			// ss
			next() {
				console.log(":点击了下一步 ");

				// 执业机构  名称地址 详细地址
				this.workingagency = uni.getStorageSync('value1');
				this.workingagency_address = uni.getStorageSync('input');
				this.workingagency_area = uni.getStorageSync('value2'); // 获取 头像地址

				// 擅长项目 ids
				this.collection_ids = uni.getStorageSync('ids');
				// 头像地址
				uni.setStorageSync('avatar', this.avatar);
				// 真实姓名
				uni.setStorageSync('nickname', this.nickname);
				// 职称
				uni.setStorageSync('positions_id', this.positions_id);
				// 执业开始时间
				uni.setStorageSync('workingtime', this.workingtime);
				// 擅长项目
				uni.setStorageSync('collection_ids', this.collection_ids);
				// 个人简介
				uni.setStorageSync('description', this.description);
				// 擅长简介
				uni.setStorageSync('selfthing', this.selfthing);

				console.log("头像地址: " + this.avatar);
				console.log("真实姓名：" + this.nickname);
				console.log("执业机构名称：" + this.workingagency);
				console.log("执业机构地区：" + this.workingagency_area);
				console.log("执业机构详细地址：" + this.workingagency_address);
				console.log("职称：" + this.positions_id);
				console.log("执业开始时间：" + this.workingtime);
				console.log("擅长项目ID:" + this.collection_ids);
				console.log("个人简介" + this.description)
				this.openinfo('/pages/qualification/qualification2/qualification2');

			},
			openinfo(url) {
				uni.navigateTo({
					url: url,
				});
			},
			chooseAvatar() {
				// 此为uView的跳转方法，详见"文档-JS"部分，也可以用uni的uni.navigateTo
				this.$u.route({
					// 关于此路径，请见下方"注意事项"
					url: '/uview-ui/components/u-avatar-cropper/u-avatar-cropper',
					// 内部已设置以下默认参数值，可不传这些参数
					params: {
						// 输出图片宽度，高等于宽，单位px
						destWidth: 300,
						// 裁剪框宽度，高等于宽，单位px
						rectWidth: 200,
						// 输出的图片类型，如果'png'类型发现裁剪的图片太大，改成"jpg"即可
						fileType: 'jpg',
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		padding: 40rpx;
	}

	.u-avatar-wrap {
		margin-top: 80rpx;
		overflow: hidden;
		margin-bottom: 80rpx;
		text-align: center;
	}

	.u-avatar-demo {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}
</style>
